package com.ruoyi.web.controller.shop.delivery;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shop.delivery.domain.ShopExpress;
import com.ruoyi.shop.delivery.service.IShopExpressService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 快递公司Controller
 * 
 * |----------------------------------------------------------------------|
 * |favorshop [简单好用，让您喜爱的小商城]
 * |----------------------------------------------------------------------|
 * |copyright www.favorshop.cn All rights reserved.
 * |----------------------------------------------------------------------|
 * | @author xuxiang
 * |----------------------------------------------------------------------|
 * | @date 2023-05-29
 * |----------------------------------------------------------------------|
 */

@Controller
@RequestMapping("/shop/express")
public class ShopExpressController extends BaseController
{
    private String prefix = "shop/delivery/express";

    @Autowired
    private IShopExpressService shopExpressService;

    @RequiresPermissions("shop:express:view")
    @GetMapping()
    public String express()
    {
        return prefix + "/express";
    }

    /**
     * 查询快递公司列表
     */
    @RequiresPermissions("shop:express:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopExpress shopExpress)
    {
        startPage();
        List<ShopExpress> list = shopExpressService.selectExpressList(shopExpress);
        return getDataTable(list);
    }

    /**
     * 导出快递公司列表
     */
    @RequiresPermissions("shop:express:export")
    @Log(title = "快递公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopExpress shopExpress)
    {
        List<ShopExpress> list = shopExpressService.selectExpressList(shopExpress);
        ExcelUtil<ShopExpress> util = new ExcelUtil<ShopExpress>(ShopExpress.class);
        return util.exportExcel(list, "快递公司数据");
    }

    /**
     * 新增快递公司
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存快递公司
     */
    @RequiresPermissions("shop:express:add")
    @Log(title = "快递公司", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopExpress shopExpress)
    {
        return toAjax(shopExpressService.insertExpress(shopExpress));
    }

    /**
     * 修改快递公司
     */
    @RequiresPermissions("shop:express:edit")
    @GetMapping("/edit/{expressId}")
    public String edit(@PathVariable("expressId") Long expressId, ModelMap mmap)
    {
        ShopExpress shopExpress = shopExpressService.selectExpressById(expressId);
        mmap.put("shopExpress", shopExpress);
        return prefix + "/edit";
    }

    /**
     * 修改保存快递公司
     */
    @RequiresPermissions("shop:express:edit")
    @Log(title = "快递公司", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopExpress shopExpress)
    {
        return toAjax(shopExpressService.updateExpress(shopExpress));
    }

	/**
	 * 删除快递公司
	 */
    @RequiresPermissions("shop:express:remove")
    @Log(title = "快递公司", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopExpressService.deleteByExpressIds(ids));
    }
}
